package com.ipzoe.app.core.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@ApiModel(description = "接口返回数据")
@Data
public class ApiResponseData<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";

    public static final String DEFAULT_ERROR_MESSAGE = "网络异常";

    public static final Integer DEFAULT_SUCCESS_CODE = 200;

    public static final Integer DEFAULT_ERROR_CODE = 500;

    /**
     * 请求是否成功
     */
    @ApiModelProperty(value = "请求是否成功")
    private Boolean success;

    /**
     * 响应状态码
     */
    @ApiModelProperty(value = "响应状态码")
    private Integer code;

    /**
     * 响应信息
     */
    @ApiModelProperty(value = "响应信息")
    private String message;

    /**
     * 响应对象
     */
    @ApiModelProperty(value = "响应对象")
    private T data;

    public ApiResponseData() {
    }

    public ApiResponseData(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static SuccessApiResponseData success() {
        return new SuccessApiResponseData();
    }

    public static <T> SuccessApiResponseData success(T t) {
        return new SuccessApiResponseData(t);
    }

    public static <T> SuccessApiResponseData success(Integer code, String message, T t) {
        return new SuccessApiResponseData(code, message, t);
    }

    public static <T> ErrorApiResponseData<T> error(String message) {
        return new ErrorApiResponseData<T>(message);
    }

    public static <T> ErrorApiResponseData<T> error(Integer code, String message) {
        return new ErrorApiResponseData<T>(code, message);
    }

    public static <T> ErrorApiResponseData<T> error(Integer code, String message, T object) {
        return new ErrorApiResponseData<T>(code, message, object);
    }
}
